﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Contacts
{
    public partial class OpForm : Form
    {
        private ToolTip t1;

        public OpForm()
        {
            InitializeComponent();
            t1 = new ToolTip();
            t1.AutoPopDelay = 5000;
            t1.InitialDelay = 1000;
            t1.ReshowDelay = 500;
            t1.ShowAlways = true;
            t1.SetToolTip(this.TDelaybox, "Enter time in whole Minutes only.");
            
        }

        /// <summary>
        /// Establish default values based on the current user settings.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OpForm_Load(object sender, EventArgs e)
        {
            // fill the time interval
            TDelaybox.Text = Properties.Settings.Default.TIME_ALIVE.ToString();

            //toggle radio button for name display
            if (Properties.Settings.Default.DISPLAY_NAME_ORDER == "LAST")
            {
                FirstLast.Checked = false;
                LastFirst.Checked = true;
            }
            else
            {
                FirstLast.Checked = true;
                LastFirst.Checked = false;
            }
            //end name toggle

            // toggle radio buttons for store display
            if (Properties.Settings.Default.STORE_SORT == "STORE")
            {
                storefirst.Checked = true;
                cityfirst.Checked = false;
            }
            else
            {
                storefirst.Checked = false;
                cityfirst.Checked = true;
            }
            // end store toggle

        }

        private void TDelaybox_TextChanged(object sender, EventArgs e)
        {
            try
            {
                Properties.Settings.Default.TIME_ALIVE = int.Parse(TDelaybox.Text);
                el.Visible = false;
                Properties.Settings.Default.Save();
            }
            catch (Exception)
            {
                
                el.ForeColor = Color.Red;
                el.Show();
                //throw;

            }

        }

        private void FirstLast_CheckedChanged(object sender, EventArgs e)
        {
            if(FirstLast.Checked) LastFirst.Checked = false;
            Properties.Settings.Default.DISPLAY_NAME_ORDER = "FIRST";
            Properties.Settings.Default.Save();
        }

        private void LastFirst_CheckedChanged(object sender, EventArgs e)
        {
            if (LastFirst.Checked) FirstLast.Checked = false;
            Properties.Settings.Default.DISPLAY_NAME_ORDER = "LAST";
            Properties.Settings.Default.Save();
        }

        private void cityfirst_CheckedChanged(object sender, EventArgs e)
        {
            if (cityfirst.Checked) storefirst.Checked = false;
            Properties.Settings.Default.STORE_SORT = "CITY";
            Properties.Settings.Default.Save();
        }

        private void storefirst_CheckedChanged(object sender, EventArgs e)
        {
            if (storefirst.Checked) cityfirst.Checked = false;
            Properties.Settings.Default.STORE_SORT = "STORE";
            Properties.Settings.Default.Save();
        }


        //TODO: add procedures here to either return proper values via properies
        //or via function calls directly to the dataset
        // Add a feature request form flyout
    }
}
